<template>
    <div class="home-comtainer">
        <el-container>
            <!-- header區域 -->
            <el-header class="el-header">
                <div class="logo">
                   <img src="../assets/logoPart.png" alt="" srcset="">
                   <span>订单管理后台</span>
                </div>
                <el-button type="info" @click="loginout">退出</el-button>
            </el-header>
            <!-- 主体内容 -->
            <el-container>
                <!-- 側邊欄 -->
                <el-aside :width="isCollapse?'64px':'200px'">
                    <div class="toggle-button" @click="toggleButton">|||</div>
                    <!-- 侧边栏菜单栏 -->   
                    <el-menu  background-color="#333744" text-color="#fff" active-text-color="#ffd04b" unique-opened :collapse="isCollapse" :collapse-transition="false" :router="true" :default-active="activePath">
                        <!-- 一级菜单 -->
                        <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
                            <!-- 一级菜单模板区域 -->
                            <template slot="title">
                            <i :class="iconsObj[item.id]"></i>
                            <span>{{item.authName}}</span>
                            </template>
                            <!-- 二级菜单 -->
                            <el-menu-item :index="'/'+itemChildren.path+''" v-for="itemChildren in item.children" :key="itemChildren.id" @click="saveNavState('/'+itemChildren.path)">
                                <!-- 一级菜单模板区域 -->
                                    <template slot="title">
                                    <i class="el-icon-menu"></i>
                                    <span>{{itemChildren.authName}}</span>
                                    </template>
                            </el-menu-item>
                        </el-submenu>
                        
                    </el-menu>
                </el-aside>
                <!-- 右側 -->
                <el-main>
                    <!-- 路由占位符 -->
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>
<script>
import axios from 'axios'
export default {
    data(){
     return{
        menulist:[],
        iconsObj:{
            125:'iconfont icon-user',
            103:'iconfont icon-bussiness-man',
            101:'iconfont icon-31dianpu',
            102:'iconfont icon-integral-fill',
            145:'iconfont icon-31goumaichongzhi'
        },
        isCollapse:false,
        isTransition:false,
        activePath:''
     }
    },
    created(){
        this.getMenuList();
        this.activePath=window.sessionStorage.getItem('activePath');
    },
    methods:{
        loginout(){
            window.sessionStorage.clear();
            this.$router.push("/login")
        },
       async getMenuList(){
         const res=  await axios.get("menus");
         console.log(res);
         if (res.data.meta.status!==200) {
             console.log("调用失败");
         }else{
            
             this.menulist=res.data.data;
              console.log("调用成功",this.menulist);
         }
         
        },
        toggleButton(){
            console.log("oc");
           
            this.isCollapse=!this.isCollapse;
            this.isTransition=!this.isTransition;
        },
        saveNavState(activePath){//保存链接存活链接
         window.sessionStorage.setItem('activePath',activePath)
         this.activePath=activePath
        }
    }
}
</script>

<style lang="less" scoped>
.home-comtainer{
    height: 100%;
}
.el-header{
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 20px;
    >div{
        display: flex;
        align-items: center;
    }
    span{
        color: #ffffff;
        line-height: 1.6;
        padding-left: 15px;
    }
}
.el-aside{
    background-color: #333744;
}
.el-main{
     background-color: #eaedf1;
}
.el-container{
    height: 100%;
}
.iconfont{
    margin-right: 10px;
}
.el-menu{
    border-right: none;
}
.toggle-button{
    background: #4a5064;
    display: flex;
    justify-content: center;
    font-size: 10px;
    color: #ffffff;
    letter-spacing: 0.2em;
    cursor: pointer;
    padding: 10px;
}
</style>

